<!-- 协议签署 -->
<template>
  <div>
    <Form ref="form" @ok="search()"></Form>
    <ZgNewPage
      ref="page"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="200"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h, i) in headers"
          :key="`column${i}`"
          :width="h.width === 0 ? 'auto' : h.width"
          align="center"
          :title="h.label"
        >
          <template slot-scope="record">
            {{ record[h.code] }}
          </template>
        </a-table-column>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
import Form from './Form'
export default {
  components: {
    Form
  },
  data () {
    return {
      uniqueName: 'test',
      pageOpt: {
        showPageTitle: false,
        showConditionBtn: true,
        showHeaderConfig: false,
        showAttachBtn: false
      },
      conditions: [
        {
          code: 'name',
          compType: '单行文本',
          label: '企业名称',
          defaultVal: '',
          extra: { placeholder: '请输入企业名称' }
        },
        { code: 'political3', compType: '字典', label: '通知类型', defaultVal: '', extra: { 字典类型: 'political' } },
        { code: 'political3', compType: '字典', label: '企业类型', defaultVal: '', extra: { 字典类型: 'political' } }
      ],
      headers: [
        { code: '1', label: '标题', isShow: true, sort: 0 },
        { code: '2', label: '内容', isShow: true, sort: 0 },
        { code: '3', label: '企业类型', isShow: true, sort: 0 },
        { code: '4', label: '企业用户', isShow: true, sort: 0 },
        { code: '5', label: '联系电话', isShow: true, sort: 0 },
        { code: '6', label: '通知方式', isShow: true, sort: 0 },
        { code: '7', label: '是否跟踪', isShow: true, sort: 0 },
        { code: '8', label: '是否已读', isShow: true, sort: 0 },
        { code: '9', label: '人工确认', isShow: true, sort: 0 },
        { code: '10', label: '人工确认时间', isShow: true, sort: 0 }
      ],
      dataBtns: [
        {
          key: 1,
          name: '详情',
          type: 'link',
          isShow: () => {
            return true
          }
        },
        { key: 2, name: '确认', type: 'link', isShow: (row) => row['9'] === '未确认' }
      ]
    }
  },
  methods: {
    search () {
      const pageRef = this.$refs.page
      if (pageRef) {
        pageRef.search()
      } else {
        setTimeout(() => {
          this.search()
        }, 50)
      }
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        {
          key: '1',
          id: '1',
          1: '授信审批',
          2: '授信审批  额度调整审批',
          3: '融资企业',
          4: '张三',
          5: '19282829292',
          6: '站内信  短信  门户',
          7: '是',
          8: '是',
          9: '已确认',
          10: '2025-01-01'
        },
        {
          key: '2',
          id: '3',
          1: '授信审批',
          2: '授信审批  额度调整审批',
          3: '融资企业',
          4: '张三',
          5: '19282829292',
          6: '站内信  短信  门户',
          7: '是',
          8: '是',
          9: '未确认',
          10: '2025-01-01'
        }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    toAdmin (opt) {
      if (opt.key === 1) {
        this.$refs.form.open('detail', opt.obj)
      } else if (opt.key === 2) {
        alert('确认')
      }
    },
    onFilter (f, param) {},
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders
        .filter((t) => {
          return t.isShow
        })
        .sort((a, b) => {
          return a.sort - b.sort
        })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
